package com.vcg.comment.utils;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class TimeUtil {


    private static Logger logger = LoggerFactory.getLogger(TimeUtil.class);

    private static final String FORMATTER = "yyyy-MM-dd";


    private static String formatTime(int num) {

        if (num == 0) {
            return "01";
        } else if (num < 10) {
            return "0" + num;
        } else {
            return "" + num;
        }
    }

    /**
     * 今天的时间
     */
    public static String getToday() {

        return new SimpleDateFormat(FORMATTER).format(new Date());
    }

    /**
     * 今天前N天的时间
     */
    public static String getBeforeToday(int n) {

        Calendar calendar = Calendar.getInstance();
        try {
            calendar.setTime(new Date());
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        calendar.add(Calendar.DATE, -n);
        return new SimpleDateFormat(FORMATTER).format(calendar.getTime());
    }

    public static String getReverseTime(long inTime) {
        long reverseTime = Long.MAX_VALUE - inTime;
        String outTime = String.valueOf(reverseTime);
        return outTime;
    }

}
